package com.anivia.system.auth.enums;

import com.anivia.common.core.constant.NumberConstant;
import com.anivia.common.core.enums.BaseEnum;
import com.anivia.common.core.enums.PlatformTypeEnum;
import com.baomidou.mybatisplus.annotation.EnumValue;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 基础菜单信息
 * </p>
 *
 * @author wangj
 */

@AllArgsConstructor
@NoArgsConstructor
@Getter
public enum ResourceBaseEnum implements BaseEnum {
    /**
     * 新增前拉取代码，更新完及时提交，不允许修改已存在的id
     */

    // a端菜单
    RESOURCE_1(1, "租户管理", ResourceTypeEnum.MENU, NumberConstant.PID, 1, "", "", "", PlatformTypeEnum.ADMIN),
    RESOURCE_2(2, "客户管理", ResourceTypeEnum.MENU, NumberConstant.PID, 1, "", "", "", PlatformTypeEnum.ADMIN),
    RESOURCE_3(3, "票据业务", ResourceTypeEnum.MENU, NumberConstant.PID, 1, "", "", "", PlatformTypeEnum.ADMIN),
    RESOURCE_4(4, "运营管理", ResourceTypeEnum.MENU, NumberConstant.PID, 1, "", "", "", PlatformTypeEnum.ADMIN),
    RESOURCE_5(5, "系统管理", ResourceTypeEnum.MENU, NumberConstant.PID, 1, "", "", "", PlatformTypeEnum.ADMIN),
    RESOURCE_6(6, "系统管理1", ResourceTypeEnum.MENU, 1, 1, "", "", "", PlatformTypeEnum.ADMIN),
    RESOURCE_7(7, "系统管理2", ResourceTypeEnum.MENU, 1, 1, "", "", "", PlatformTypeEnum.ADMIN),
    RESOURCE_8(8, "系统管理3", ResourceTypeEnum.MENU, 1, 1, "", "", "", PlatformTypeEnum.ADMIN),
    // b端菜单
    RESOURCE_9(9, "客户管理", ResourceTypeEnum.MENU, NumberConstant.PID, 1, "", "", "", PlatformTypeEnum.TENANT),
    ;

    @EnumValue
    private Integer id;
    /**
     * 名称
     */
    private String name;
    /**
     * 资源类型
     */
    private ResourceTypeEnum type;
    /**
     * 父id
     */
    private Integer pid;
    /**
     * 默认权重（排序）
     */
    private Integer weight;
    /**
     * 图标
     */
    private String icon;
    /**
     * 路由
     */
    private String route;
    /**
     * 权限编码
     */
    private String authCode;
    /**
     * 平台类型
     */
    private PlatformTypeEnum platformType;

    @Override
    public Integer getCode() {
        return id;
    }

    @Override
    public String getDesc() {
        return name;
    }

    public static ResourceBaseEnum getByCode(Integer id) {
        for (ResourceBaseEnum item : values()) {
            if (item.id.equals(id)) {
                return item;
            }
        }
        return null;
    }

    public static List<ResourceBaseEnum> valuesByPlatformType(PlatformTypeEnum platformType) {
        return Arrays.stream(values()).filter(item -> item.platformType.equals(platformType)).collect(Collectors.toList());
    }
}